package com.htdata.iiot.file.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.htiiot.common.db.DbConnectionPool;
import com.htiiot.common.db.JDBCUtils;

/**
 * Created by liuming on 2017/04/07.
 */
public class TenantDao {
	
	/**
     * 根据apikey获取租户信息
     *
     * @param apikey
     * @return
     * @throws SQLException
     */
    public static String getTenantById(int id) {
    	DbConnectionPool pool = DbConnectionPool.getPool();
        String sql = "select api_key from tenant where id=? and deleted=0";
        Connection conn = pool.getConnection();
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement(sql);
            ps.setInt(1, id);
            rs = ps.executeQuery();
            if(rs!=null && rs.next()){
            	return rs.getString(1);
            }
        } catch (SQLException e) {
        	e.printStackTrace();
        } finally {
            JDBCUtils.close(ps, rs, conn);
        }
        return null;
    }
    
}
